package com.example.job10redisscene;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class BitMap {

    @Autowired
    private RedisTemplate redisTemplate;

    public void distinct() {
        String idBitKey = "idBitKey";
        redisTemplate.delete(idBitKey);
        List<Integer> idList = new ArrayList<>();
        idList.add(1);
        idList.add(1);
        idList.add(1);
        idList.add(3);
        for (Integer id : idList) {
            redisTemplate.opsForValue().setBit(idBitKey, id, true);
        }
        for (int i = 1;i<4;i++){
            final Boolean bit = redisTemplate.opsForValue().getBit(idBitKey, i);
            if (bit) {
                System.out.println(i);
            }
        }
    }

    // 用户签到
    // 统计活跃用户
    // 用户在线状态
}
